package br.com.portalaberto.telas;

import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class SplashScreen extends Canvas{
	private Display display;
	private Displayable next;
	private Timer timer = new Timer();
	private Image image;

	public SplashScreen(Display display, Displayable next){

		this.display = display;
		this.next = next;

		display.setCurrent(this);
	}

	protected void keyPressed(int keyCode){
		dismiss();
	}

	protected void paint( Graphics g ){
		try{
			image = Image.createImage("/splash.png");
		}catch (Exception e) { }

		g.setColor(0x001B1432);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.drawImage(image, getWidth()/2, getHeight()/2,Graphics.HCENTER|Graphics.VCENTER);

	}

	protected void pointerPressed(int x, int y){
		dismiss();
	}

	protected void showNotify(){
		timer.schedule(new CountDown(), 100000);
	}

	private void dismiss(){
		timer.cancel();
		display.setCurrent(next);
	}

	private class CountDown extends TimerTask {
		public void run(){
			dismiss();
		}
	}
}
